//! Loa.debug.js
//

(function() {

Type.registerNamespace('Loa');

////////////////////////////////////////////////////////////////////////////////
// Loa.TimerPage

Loa.TimerPage = function Loa_TimerPage() {
    /// <field name="indicator" type="jQueryObject" static="true">
    /// </field>
    /// <field name="quarterBell" type="Boolean" static="true">
    /// </field>
    /// <field name="running" type="Boolean" static="true">
    /// </field>
    /// <field name="timer" type="Loa.TimerGadget" static="true">
    /// </field>
    /// <field name="waiter" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="quarterBellKey" type="String" static="true">
    /// </field>
    /// <field name="sound0" type="jQueryObject" static="true">
    /// </field>
    /// <field name="sound1" type="jQueryObject" static="true">
    /// </field>
    /// <field name="sound2" type="jQueryObject" static="true">
    /// </field>
    /// <field name="sound4" type="jQueryObject" static="true">
    /// </field>
    /// <field name="bellSound" type="String" static="true">
    /// </field>
    /// <field name="clinkSound" type="String" static="true">
    /// </field>
    /// <field name="whiperwillSound" type="String" static="true">
    /// </field>
    /// <field name="catCallSound" type="String" static="true">
    /// </field>
    /// <field name="beginSound" type="String" static="true">
    /// </field>
    /// <field name="doneSound" type="String" static="true">
    /// </field>
}
Loa.TimerPage.Page = function Loa_TimerPage$Page() {
    if (!ThemeYoshi.get_isAdmin()) {
        return;
    }
    if (Nsb.Storage.getLocal('TmrPgQtrBell') == null) {
        Nsb.Storage.setLocal('TmrPgQtrBell', true);
    }
    Loa.TimerPage.quarterBell = Nsb.Storage.getLocal('TmrPgQtrBell');
    Loa.TimerPage.sound0 = $("<audio preload='auto'/>").attr('src', Loa.TimerPage.beginSound);
    Loa.TimerPage.sound1 = $("<audio preload='auto'/>").attr('src', 'http://www.rangde.org/static/bell-ring-01.mp3');
    Loa.TimerPage.sound2 = $("<audio preload='auto'/>").attr('src', Loa.TimerPage.doneSound);
    Loa.TimerPage.sound4 = $("<audio preload='auto'/>").attr('src', Loa.TimerPage.catCallSound);
    Loa.TimerPage.indicator = $('#Indicator').click(function() {
        Loa.TimerPage.stopSound();
    }).html('');
    $('#StartTimerBtn').click(Loa.TimerPage.startTimerEv);
    $('#QuarterBell').click(Loa.TimerPage.quarterBellEv).html((Loa.TimerPage.quarterBell) ? 'ON' : 'OFF').css({ cursor: 'pointer' });
}
Loa.TimerPage.startTimerEv = function Loa_TimerPage$startTimerEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var tgo = new Loa.TimerGadgetOptions();
    tgo.trigger = Loa.TimerPage.trigger;
    tgo.start = Loa.TimerPage.start;
    tgo.stop = Loa.TimerPage.stop;
    tgo.cancel = Loa.TimerPage.cancel;
    tgo.element = Loa.TimerPage.indicator;
    tgo.interval = 1000;
    tgo.duration = (e.shiftKey) ? 4000 : 68000;
    tgo.marks = (e.shiftKey) ? [2] : [17,34,51];
    if (Loa.TimerPage.running) {
        tgo.done = true;
        if (Loa.TimerPage.timer != null) {
            Loa.TimerPage.timer.cancel();
        }
        else {
            Loa.TimerPage.cleanup();
        }
        return;
    }
    Loa.TimerPage.running = true;
    $('#StartTimerBtn').html('reset timer');
    Loa.TimerPage.play(Loa.TimerPage.sound0, 1);
    Loa.TimerPage.waiter = window.setTimeout(function() {
        Loa.TimerPage.timer = new Loa.TimerGadget(tgo);
    }, 6200);
}
Loa.TimerPage.play = function Loa_TimerPage$play(sound, volume) {
    /// <param name="sound" type="jQueryObject">
    /// </param>
    /// <param name="volume" type="Number">
    /// </param>
    sound[0].volume = volume;
    sound[0].play();
}
Loa.TimerPage.trigger = function Loa_TimerPage$trigger(tgo) {
    /// <param name="tgo" type="Loa.TimerGadgetOptions">
    /// </param>
    tgo.element.html(tgo.tick.toString());
    if (Loa.TimerPage.quarterBell && tgo.marks.contains(tgo.tick)) {
        Loa.TimerPage.play(Loa.TimerPage.sound1, 0.1);
    }
}
Loa.TimerPage.start = function Loa_TimerPage$start(tgo) {
    /// <param name="tgo" type="Loa.TimerGadgetOptions">
    /// </param>
    Loa.TimerPage.indicator.html('0');
}
Loa.TimerPage.stop = function Loa_TimerPage$stop(tgo) {
    /// <param name="tgo" type="Loa.TimerGadgetOptions">
    /// </param>
    Loa.TimerPage.indicator.html('');
    Loa.TimerPage.stopSound();
}
Loa.TimerPage.stopSound = function Loa_TimerPage$stopSound() {
    Loa.TimerPage.play(Loa.TimerPage.sound2, 0.75);
    Loa.TimerPage.waiter = window.setTimeout(function() {
        Loa.TimerPage.play(Loa.TimerPage.sound4, 0.1);
        Loa.TimerPage.waiter = window.setTimeout(Loa.TimerPage.cleanup, 1000);
    }, 3500);
}
Loa.TimerPage.cancel = function Loa_TimerPage$cancel(tgo) {
    /// <param name="tgo" type="Loa.TimerGadgetOptions">
    /// </param>
    Loa.TimerPage.cleanup();
}
Loa.TimerPage.cleanup = function Loa_TimerPage$cleanup() {
    window.clearTimeout(Loa.TimerPage.waiter);
    Loa.TimerPage.timer = null;
    $('#StartTimerBtn').html('start timer');
    Loa.TimerPage.indicator.html('');
    Loa.TimerPage.running = false;
}
Loa.TimerPage.quarterBellEv = function Loa_TimerPage$quarterBellEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    Loa.TimerPage.quarterBell = !Loa.TimerPage.quarterBell;
    $('#QuarterBell').html((Loa.TimerPage.quarterBell) ? 'ON' : 'OFF');
    Nsb.Storage.setLocal('TmrPgQtrBell', Loa.TimerPage.quarterBell);
}


////////////////////////////////////////////////////////////////////////////////
// Loa.TimerGadget

Loa.TimerGadget = function Loa_TimerGadget(options) {
    /// <param name="options" type="Loa.TimerGadgetOptions">
    /// </param>
    /// <field name="_opt" type="Loa.TimerGadgetOptions">
    /// </field>
    this._opt = options;
    if (this._opt.done) {
        this.cancel();
        return;
    }
    this._opt.startTm = new Date().getTime();
    this._opt.stopTm = this._opt.startTm + this._opt.duration;
    if (this._opt.start != null) {
        this._opt.start(this._opt);
    }
    this._opt.timer = window.setInterval(ss.Delegate.create(this, this.trigger), this._opt.interval);
}
Loa.TimerGadget.prototype = {
    _opt: null,
    
    trigger: function Loa_TimerGadget$trigger() {
        this._opt.tick++;
        if (this._opt.trigger != null) {
            this._opt.trigger(this._opt);
        }
        if (new Date().getTime() > this._opt.stopTm) {
            window.clearInterval(this._opt.timer);
            if (this._opt.stop != null) {
                this._opt.stop(this._opt);
            }
            this._opt.done = true;
        }
    },
    
    cancel: function Loa_TimerGadget$cancel() {
        this._opt.done = true;
        window.clearInterval(this._opt.timer);
        if (this._opt.cancel != null) {
            this._opt.cancel(this._opt);
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// Loa.TimerGadgetOptions

Loa.TimerGadgetOptions = function Loa_TimerGadgetOptions() {
    /// <field name="startTm" type="Number" integer="true">
    /// </field>
    /// <field name="stopTm" type="Number" integer="true">
    /// </field>
    /// <field name="tick" type="Number" integer="true">
    /// </field>
    /// <field name="interval" type="Number" integer="true">
    /// </field>
    /// <field name="duration" type="Number" integer="true">
    /// </field>
    /// <field name="start" type="System.Action`1">
    /// </field>
    /// <field name="stop" type="System.Action`1">
    /// </field>
    /// <field name="trigger" type="System.Action`1">
    /// </field>
    /// <field name="cancel" type="System.Action`1">
    /// </field>
    /// <field name="marks" type="Array">
    /// </field>
    /// <field name="timer" type="Number" integer="true">
    /// </field>
    /// <field name="element" type="jQueryObject">
    /// </field>
    /// <field name="done" type="Boolean">
    /// </field>
}
Loa.TimerGadgetOptions.prototype = {
    startTm: 0,
    stopTm: 0,
    tick: 0,
    interval: 1000,
    duration: 1000,
    start: null,
    stop: null,
    trigger: null,
    cancel: null,
    marks: null,
    timer: 0,
    element: null,
    done: false
}


Loa.TimerPage.registerClass('Loa.TimerPage');
Loa.TimerGadget.registerClass('Loa.TimerGadget');
Loa.TimerGadgetOptions.registerClass('Loa.TimerGadgetOptions');
Loa.TimerPage.indicator = null;
Loa.TimerPage.quarterBell = true;
Loa.TimerPage.running = false;
Loa.TimerPage.timer = null;
Loa.TimerPage.waiter = 0;
Loa.TimerPage.quarterBellKey = 'TmrPgQtrBell';
Loa.TimerPage.sound0 = null;
Loa.TimerPage.sound1 = null;
Loa.TimerPage.sound2 = null;
Loa.TimerPage.sound4 = null;
Loa.TimerPage.bellSound = 'http://www.rangde.org/static/bell-ring-01.mp3';
Loa.TimerPage.clinkSound = 'http://soundjax.com/reddo/31398%5Eglass-clink-3.mp3';
Loa.TimerPage.whiperwillSound = 'http://soundjax.com/reddo/70117%5Ebird1.mp3';
Loa.TimerPage.catCallSound = Uri.app('pg/gigs/68_second_timer/Sounds/CatCall.mp3');
Loa.TimerPage.beginSound = Uri.app('pg/gigs/68_second_timer/Sounds/Begin.mp3');
Loa.TimerPage.doneSound = Uri.app('pg/gigs/68_second_timer/Sounds/Done.mp3');
})();

//! This script was generated using Script# v0.7.4.0
